import {observable, action} from 'mobx';
import pagination from "@/stores/common/Pagination";
import * as InfoApi from "@/service/api/CrossBorderHeadTrackingApi";

class CrossBorderHeadTrackingStore {
  @observable list = [{key:"key_478qwe45",id:"1",name:"你好"}];
  @observable item;
  @observable pagination = new pagination();
    
  @action saveItem = (obj) => {
    const that = this;
    InfoApi.ADDITEM(obj).then(rs=>{
      that.hiddenDialog();
    })
  }

  @action upItem = (obj) => {
    const that = this;
    InfoApi.UPITEM(obj).then(rs=>{
      that.hiddenDialog();
    })
  }
  @action hiddenDialog = () => {
    this.item = undefined;
  }
  @action addShow = () => {
    this.item = {};
  }
  @action editShow = (item) => {
    this.item = item;
  }
  @action removeItem = (id) => {
    const that = this;
    InfoApi.DELITEM({id}).then(rs=>{ 
      that.getList();
    })
  }
  @action showPropup = bool => {
    this.item = undefined;
  };
  @action hideProup = () => {
    this.item = undefined;
    this.getList();
  };
  @action updateItem = info => {
    const that = this;
    InfoApi.UPITEM(info).then(rs=>{ 
      that.hideProup();
    })
  };
  @action init = ()=> {
    this.pagination.getList = this.getList;
    this.getList();
  }
  @action setList = (data) => {
    this.pagination.init (data);
    this.list = data.data;
  }
  @action getList = () => {
    const that = this;
    var params = {
      currentPage: this.pagination.currentPage,
      pageSize: this.pagination.pageSize
    }
    InfoApi.GETLIST(params).then(rs=>{
      if(rs.success) {
        that.setList(rs);
      }
    })
  };
}

export default new CrossBorderHeadTrackingStore();